package org.starlight.user.serivce.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.starlight.delete.DeleteRecordHelper;
import org.starlight.delete.enums.TableEnum;
import org.starlight.user.entity.Dept;
import org.starlight.user.repository.DeptRepository;
import org.starlight.user.serivce.DeptService;

/**
 * @author huangyong
 * @data 2025/2/28
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DeptServiceImpl implements DeptService {
    private final DeptRepository deptRepository;

    @Override
    public void save(Dept dept) {
        deptRepository.save(dept);
    }

    @Override
    public void del(Integer id) {
        // todo 删除部门之前，需要判断部门下是否有用户，如果有用户，则不允许删除
        DeleteRecordHelper.saveDeleteRecord(TableEnum.dept, deptRepository.findById(id).orElse(null));
        deptRepository.deleteById(id);
    }
}
